package com.intermancer.predictor.gene.logic;

import java.util.List;

import com.intermancer.predictor.gene.AbstractGene;
import com.intermancer.predictor.mutation.MutationAssistant;
import com.intermancer.predictor.mutation.MutationCommand;
import com.intermancer.predictor.mutation.MutationContext;

public abstract class AbstractLogicGene extends AbstractGene {
	
	public class LogicSignMC implements MutationCommand {

		public void execute(MutationAssistant mutationAssistant,
				MutationContext context) {
			lessThanEqualFlag = !lessThanEqualFlag;
		}

	}
	
	public abstract int getOffsetsSize();
	
	private int[] offsets;
	private boolean lessThanEqualFlag = true;
	
	public AbstractLogicGene() {
		super();
		offsets = new int[getOffsetsSize()];
		for(int i = 0; i < getOffsetsSize(); i++) {
			offsets[i] = -1 - i;
		}
	}

	@Override
	public int[] getOffsets() {
		return offsets;
	}
	
	public void setOffsets(int[] offsets) {
		this.offsets = offsets;
	}
	
	protected boolean compare(double val1, double val2) {
		if(val1 <= val2) {
			return lessThanEqualFlag;
		} else  {
			return !lessThanEqualFlag;
		}
	}

	@Override
	public List<MutationCommand> assembleMutationCommandList() {
		List<MutationCommand> commands = super.assembleMutationCommandList();
		commands.add(new LogicSignMC());
		return commands;
	}

}
